<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>深度克隆</title>
</head>
<body>
<script>
function Car1 (id) {
	this.id = id;
	// 没有 return,默认会返回 this
}
Car1.prototype = {
	getId: function() {
		return this.id;
	},
	setId: function(id) {
		this.id = id;
	}
};
const car11 = new Car1(11);
console.log(car11);
</script>
<script>
function Car2 (id) {
	this.id = id;
	// 返回了一个对象,则 this 指向该对象,生成的对象就读取不到 this.id
	return {
		text: 2222
	};
}
Car2.prototype = {
	getId: function() {
		return this.id;
	},
	setId: function(id) {
		this.id = id;
	}
};
const car2 = new Car2(11);
console.log(car2);
console.log(car2.text);//2222
console.log(car2.id);//undefined
</script>
<script>
function Car3 (id) {
	this.id = id;
	// 返回 null,true,1等,this 则不会指向该返回值,依然可以访问到 this.id
	return null;
}
Car3.prototype = {
	getId: function() {
		return this.id;
	},
	setId: function(id) {
		this.id = id;
	}
};
const car3 = new Car3(11);
console.log(car3);
console.log(car3.id);//11
</script>
</body>
</html>